package com.satchi.struts.action.balance;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.satchi.hib.pojo.FinBalance;
import com.satchi.hib.pojo.FinCustomer;
import com.satchi.service.GetBalanceService;
import com.satchi.service.GetCustomerService;
import com.satchi.struts.ActionHelper;

public class ForwardBalanceaddAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String modifyId = request.getParameter("modifyId");
		
		GetCustomerService customerServ = new GetCustomerService();
		GetBalanceService balanceServ = new GetBalanceService();
		List<FinCustomer> customers = null;
		
		if(!ActionHelper.IsEmpty(modifyId)) {
			FinBalance b = balanceServ.get(modifyId);
			if(!b.getShop().getIsenable()){
				customers = new ArrayList<FinCustomer>();
				customers.add(b.getFinCustomer());
			}
			request.setAttribute("modifyObject", b);
		}else{
			request.setAttribute("balanceId", balanceServ.getMaxId());
		}
		if (customers == null)
			customers = customerServ.getParentCustomers();
		
		request.setAttribute("customers", customers);
		return mapping.findForward("success");
	}
	
}
